package com.wooshow.base.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

public class Date extends TagSupport {

	private static final long serialVersionUID = 4179331287693125887L;

	private static final Log log = LogFactory.getLog(Date.class);
	
	private Object value;
	
	private String format;
	
    public int doStartTag() throws JspException {
    	if (StringUtils.isEmpty(format)) {
			try {
				format = pageContext.getServletContext().getInitParameter("defaultDateTimeFormat");
			} catch (Exception e) {
				format = DateFormatUtils.ISO_DATETIME_FORMAT.getPattern();
			}
		}
		log.debug(this);
		// DateFormatUtils dataFormatUtils = new DateFormatUtils();
	    return super.doStartTag();
    }
    
    public String toString() {
	    return ToStringBuilder.reflectionToString(this);
    }

	public Object getValue() {
    	return value;
    }

	public void setValue(Object value) throws JspException {
		this.value = ExpressionEvaluatorManager.evaluate("wooshow", value.toString(), Object.class, this, pageContext);
    }

	public String getFormat() {
    	return format;
    }

	public void setFormat(String format) {
    	this.format = format;
    }

	
	
}
